package com.ssh.test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
	
	private static HibernateUtil instance;
	private SessionFactory factory;
	
	private HibernateUtil() {
		Configuration cfg = new Configuration().configure();
		factory = cfg.buildSessionFactory();
	}
	
	public static HibernateUtil getInstance() {
		if(instance == null) {
			instance = new HibernateUtil();
		}
		return instance;
	}
	
	public Session openSession() {
		return factory.openSession();
	}
	
	public void closeSession(Session session) {
		if(session != null) {
			session.close();
		}
	}
}
